package com.itheima.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

// 过滤器入门
@Slf4j
// @WebFilter("/*") //可以省略urlPatterns
public class EFilter implements Filter {
    // 过滤器初始化了(保安上班了)
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("DemoFilter init");
    }

    // 过滤方法(保安拦截人/请求)
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("第二个过滤器EFilter doFilter 拦截到了请求 放行前");

        // 放行
        filterChain.doFilter(servletRequest, servletResponse);

        log.info("第二个过滤器EFilter  doFilter 拦截到了请求 放行后");
    }

    // 过滤器销毁了(保安下班啦)
    @Override
    public void destroy() {
        log.info("DemoFilter destroy");
    }
}
